﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace 玩具商城管理系统
{
    public partial class login : Form
    {
        public login()
        {
            InitializeComponent();
        }
        public static string username = "";
        public static string clientid = "";
        public static bool Bflag = false;//false是普通员工，true是管理员
        public static bool Dflag=false;//false是普通员工，true是销售部员工
        private void button1_Click(object sender, EventArgs e)
        {
            if(txtName.Text=="" || txtPwd.Text=="")
            {
                MessageBox.Show("请输入用户名或密码错误");
            }
            else
            {
                DB.GetCn();
                if(radioButton1.Checked)
                {
                    string str = "select * from client where client_name='"
                        + txtName.Text + "'and client_pwd ='" + txtPwd.Text + "'";
                    DataTable dt = DB.GetDataSet(str);
                    if(dt.Rows.Count > 0 ) 
                    {
                        MessageBox.Show("登录成功");
                        username = txtName.Text;
               
                        Form1.flag = 1;
                        Form1.Aflag = true;
                        newwin.flag = 1;
                        newwin.Aflag = true;
                        znew.订购.Aflag = true;

                        this.Close();
                        this.DialogResult = DialogResult.OK;
                        
                    }
                    else
                    {
                        MessageBox.Show("用户名或密码错误");
                    }
                }
                if(radioButton2.Checked) 
                { 
                    string str="select * from employee where employee_name='"
                        +txtName.Text+"'and employee_pwd='"+txtPwd.Text + "'";
                    DataTable dt = DB.GetDataSet(str);
                    if(dt.Rows.Count > 0 )
                    {
                        Bflag = true;
                        MessageBox.Show("登录成功");
                        username = txtName.Text;
                        Form1.flag = 2;
                        newwin.flag = 2;
                        this.Close();
                        Tm t1 = new Tm();
                        t1.ShowDialog();
                    }
                    else
                    {
                        MessageBox.Show("用户名或密码错误");
                    }
                }
                if (radioButton3.Checked)
                {
                    string str = "select * from employee where employee_name='"
                        + txtName.Text + "'and employee_pwd='" + txtPwd.Text + "'";
                    DataTable dt = DB.GetDataSet(str);
                    if (dt.Rows.Count > 0)
                    {
                        MessageBox.Show("登录成功");
                        username = txtName.Text;
                       
                        if (dt.Rows[0][8].ToString() == "5")
                        {
                            Dflag = true;
                        }
                        else
                        {
                            Dflag = false;
                        }
                        this.Close();
                        Tm t1 = new Tm();
                        t1.ShowDialog();

                    }
                    else
                    {
                        MessageBox.Show("用户名或密码错误");
                    }
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void txtPwd_TextChanged(object sender, EventArgs e)
        {

        }

        private void login_Load(object sender, EventArgs e)
        {

        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {

        }
    }
}
